package com.icloud.cer.rest.web.bean;

public class ArrayTime {
	private long[] time;
	private int length;// 默认为十次（10s内刷新10次则违反规则）

	public ArrayTime(int size) {
		length = size;
		init(size);
	}

	public void init(int size) {
		time = new long[size];
	}

	public long[] getTime() {
		return time;
	}

	public void setTime(long[] time) {
		this.time = time;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public long getLast() {
		return this.time[length - 1];
	}

	public long getFirst() {
		return this.time[0];
	}

	public void insert(long nextTime) {
		// 数组已经满了
		if (this.getLast() != 0) {
			// 去掉首元素，将数组元素顺序前移，nextTime插到最后
			for (int i = 0; i < this.length - 1; i++) {
				time[i] = time[i+1];
			}
			this.time[length - 1] = nextTime;
			for (int i = 0; i < time.length; i++) {
				System.out.println("time=>:" + time[i]);
			}
		} else {
			// 插到下一个，不用排序
			int j = 0;
			while (time[j] != 0) {
				j++;
			}
			time[j] = nextTime;
			for (int i = 0; i < time.length; i++) {
				System.out.println("time->:" + time[i]);
			}
		}
	}
}
